﻿package com.firewolf.chars.main;

import java.nio.charset.Charset;
import java.util.Map;
import java.util.Set;

import org.junit.Test;

import com.firewolf.chars.utils.CharSetUtil;

public class TestMain {
	/**
	 * 获取ISO-8859-1的所有别名
	 */
	@Test
	public void test_getOtherNameOfOneChar() {
		Set<String> set = CharSetUtil.getCharOtherName("ISO-8859-1");
		System.out.println("ISO-8859-1的所有别名如下");
		for(String name : set){
			System.out.println(name);
		}
	}

	/**
	 * 获取当前环境所有可用的字符集
	 */
	@Test
	public void test_getAllavilAbleChars() {
		Map<String,Charset> map = CharSetUtil.getAvilableChars();
		System.out.println("当前环境所有可用的字符编码如下");
		for(String name : map.keySet()){
			System.out.println(name);
		}
	}
	
	/**
	 * 测试编码
	 */
	@Test
	public void testEncode(){
		byte[] encodedBytes = CharSetUtil.encodeStrByOneChar("ISO-8859-1", "测试编码程序");
		System.out.println(encodedBytes.toString());
	}

	public void testDecode(){
		byte[] encodedBytes = CharSetUtil.encodeStrByOneChar("UTF-8", "测试编码程序");
		String decodeStr = CharSetUtil.decodeBytesByOneChar("UTF-8", encodedBytes, 0, encodedBytes.length);
		System.out.println(decodeStr);
	}
}
